·<template>
    <van-nav-bar title="搜索页" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" fixed />
    <div style="height: 45px;"></div>
    <van-search v-model="searchval" placeholder="请输入搜索关键词" />
    <van-skeleton v-show="ispd" title :row="10" />
    <van-cell-group v-for="item in searchData" v-if="status">
        <router-link :to="'/detail/' + item.goods_id">
            <van-cell :title="item.goods_name" />
        </router-link>
    </van-cell-group>
    <van-empty v-else image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" image-size="80"
        description="暂无搜索数据" />
</template>

<script setup>
import { ref, watch } from 'vue'
import { searchApi } from '@/api/api'
import _ from 'lodash'
let searchData = ref([])
let searchval = ref('')
let status = ref(false)
let ispd = ref(false)
watch(searchval, _.debounce((val) => {
    searchApi(val).then(res => {
        console.log('搜索数据', res);
        ispd.value = true
        searchData.value = res.data.message
        if (searchData.value == null) {
            status.value = false
        } else {
            if (searchData.value.length == 0) {
                status.value = false
            } else {
                status.value = true
            }
        }
    })
}, 3000))
setInterval(() => {
    ispd.value = false
}, 2000)
</script>

<style lang="scss" scoped></style>